package com.ruoyi.employee.service.impl;

import java.util.List;

import com.ruoyi.common.md5.MD5;
import com.ruoyi.common.md5.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.employee.mapper.CrmEmployeeMapper;
import com.ruoyi.employee.domain.CrmEmployee;
import com.ruoyi.employee.service.ICrmEmployeeService;

/**
 * 客户员工Service业务层处理
 * 
 * @author hct
 * @date 2022-02-11
 */
@Service
public class CrmEmployeeServiceImpl implements ICrmEmployeeService 
{
    @Autowired
    private CrmEmployeeMapper crmEmployeeMapper;

    /**
     * 查询客户员工
     * 
     * @param id 客户员工主键
     * @return 客户员工
     */
    @Override
    public CrmEmployee selectCrmEmployeeById(Long id)
    {
        return crmEmployeeMapper.selectCrmEmployeeById(id);
    }

    /**
     * 查询客户员工列表
     * 
     * @param crmEmployee 客户员工
     * @return 客户员工
     */
    @Override
    public List<CrmEmployee> selectCrmEmployeeList(CrmEmployee crmEmployee)
    {
        return crmEmployeeMapper.selectCrmEmployeeList(crmEmployee);
    }

    /**
     * 新增客户员工
     * 
     * @param crmEmployee 客户员工
     * @return 结果
     */
    @Override
    public int insertCrmEmployee(CrmEmployee crmEmployee)
    {
        return crmEmployeeMapper.insertCrmEmployee(crmEmployee);
    }

    /**
     * 修改客户员工
     * 
     * @param crmEmployee 客户员工
     * @return 结果
     */
    @Override
    public int updateCrmEmployee(CrmEmployee crmEmployee)
    {
        return crmEmployeeMapper.updateCrmEmployee(crmEmployee);
    }

    /**
     * 批量删除客户员工
     * 
     * @param ids 需要删除的客户员工主键
     * @return 结果
     */
    @Override
    public int deleteCrmEmployeeByIds(Long[] ids)
    {
        return crmEmployeeMapper.deleteCrmEmployeeByIds(ids);
    }

    /**
     * 删除客户员工信息
     * 
     * @param id 客户员工主键
     * @return 结果
     */
    @Override
    public int deleteCrmEmployeeById(Long id)
    {
        return crmEmployeeMapper.deleteCrmEmployeeById(id);
    }

    @Override
    public String employeeLogin(String mobile,String password){
        CrmEmployee crmEmployee=new CrmEmployee();
        crmEmployee.setMobile(mobile);
        crmEmployee.setPassword(MD5.md5Hex(mobile+password));
        List<CrmEmployee>  list= crmEmployeeMapper.selectCrmEmployeeList(crmEmployee);
        if(list!=null && list.size()>0){
            return mobile+password;
        }
        return "token";
    }
    @Override
    public Boolean checkPhoneUnique(String mobile){
        CrmEmployee info = crmEmployeeMapper.findByPhoneNumber(mobile);
        if (info!=null  && info.getId().longValue()>0)
        {
            return true;
        }
        return false;
    }
}
